home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / Professional Programmer XSL IDE / Xselerator25.msi / Data.Cab / F29060_elimError.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2001-11-07  |  4.6 KB  |  134 lines

  1. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  2. xmlns:roundLog2="roundLog2"
  3. >
  4.   <xsl:import href="roundLog2.xsl"/>
  5.   
  6.   <xsl:template name="elimError">
  7.     <xsl:param name="pList" select="/.."/>
  8.     <xsl:param name="pOrder" select="-9999999"/>
  9.     <xsl:param name="pv2__N" select="0"/>
  10.     
  11.     <xsl:choose>
  12.       <xsl:when test="count($pList) < 3">
  13.         <xsl:copy-of select="$pList"/>
  14.       </xsl:when>
  15.       <xsl:otherwise>
  16.         <xsl:variable name="vOrder">
  17.             <xsl:choose>
  18.               <xsl:when test="$pOrder < -9999998">
  19.                 <xsl:call-template name="getOrder">
  20.                   <xsl:with-param name="pList" select="$pList"/>
  21.                 </xsl:call-template>
  22.               </xsl:when>
  23.               <xsl:otherwise>
  24.                 <xsl:value-of select="$pOrder"/>
  25.               </xsl:otherwise>
  26.             </xsl:choose>
  27.         </xsl:variable> 
  28.       
  29.         <xsl:variable name="v2__N">
  30.           <xsl:choose>
  31.               <xsl:when test="$pv2__N = 0">
  32.                   <xsl:call-template name="pow">
  33.                     <xsl:with-param name="base" select="2"/>
  34.                     <xsl:with-param name="pow" select="$vOrder"/>
  35.                   </xsl:call-template>
  36.               </xsl:when>
  37.               <xsl:otherwise>
  38.                   <xsl:value-of select="$pv2__N"/>
  39.               </xsl:otherwise>
  40.           </xsl:choose>
  41.         </xsl:variable>
  42.         
  43.         <xsl:element name="{name($pList[1])}">
  44.           <xsl:value-of select="($pList[2] * $v2__N - $pList[1]) 
  45.                                  div 
  46.                                   ($v2__N - 1)"/>
  47.         </xsl:element>
  48.         
  49.         <xsl:variable name="vNewList" select="$pList[position() > 1]"/>
  50.         
  51.         <xsl:variable name="vNewOrder">
  52.             <xsl:call-template name="getOrder">
  53.               <xsl:with-param name="pList" select="$vNewList"/>
  54.             </xsl:call-template>
  55.         </xsl:variable> 
  56.         <xsl:call-template name="elimError">
  57.             <xsl:with-param name="pList" select="$vNewList"/>
  58.             <xsl:with-param name="pOrder" select="$vNewOrder"/>
  59.             <xsl:with-param name="pv2__N" select="$v2__N"/>
  60.         </xsl:call-template>
  61.         
  62.       </xsl:otherwise>
  63.     </xsl:choose>
  64.   </xsl:template>
  65.   
  66.   <xsl:template name="getOrder">
  67.     <xsl:param name="pList" select="/.."/>
  68.     
  69.     <xsl:choose>
  70.       <xsl:when test="count($pList) < 3">1</xsl:when>
  71.       <xsl:otherwise>
  72.         <xsl:variable name="v1" select="($pList[1] - $pList[3])
  73.                                        div 
  74.                                          ($pList[2] - $pList[3])
  75.                                          - 1"/>
  76.         <xsl:variable name="v2">
  77.           <xsl:choose>
  78.             <xsl:when test="$v1 > 0">
  79.               <xsl:value-of select="$v1"/>
  80.             </xsl:when>
  81.             <xsl:when test="$v1 < 0">
  82.               <xsl:value-of select="(-1) * $v1"/>          
  83.             </xsl:when>
  84.             <xsl:otherwise>1</xsl:otherwise>
  85.           </xsl:choose>
  86.         </xsl:variable>
  87.         
  88.         <xsl:value-of select="roundLog2:roundLog2(string($v2))"/>
  89.       </xsl:otherwise>
  90.     </xsl:choose>
  91.   </xsl:template>
  92.   
  93.    <xsl:template name="pow">
  94.         <xsl:param name="base" select="1"/>
  95.         <xsl:param name="pow" select="0"/>
  96.         <xsl:param name="tmpResult" select="1"/>
  97.  
  98.         <xsl:variable name="result">
  99.             <xsl:choose>
  100.                 <xsl:when test="$pow >= 0">
  101.                     <xsl:value-of select="$tmpResult * $base"/>
  102.                 </xsl:when>
  103.                 <xsl:otherwise>
  104.                     <xsl:value-of select="$tmpResult div $base"/>
  105.                 </xsl:otherwise>
  106.            </xsl:choose>
  107.         </xsl:variable>
  108.  
  109.         <xsl:variable name="incr">
  110.             <xsl:choose>
  111.                 <xsl:when test="$pow >= 0">
  112.                     <xsl:value-of select="- 1"/>
  113.                 </xsl:when>
  114.                 <xsl:otherwise>
  115.                     <xsl:value-of select="1"/>
  116.                 </xsl:otherwise>
  117.             </xsl:choose>
  118.         </xsl:variable>
  119.  
  120.         <xsl:choose>
  121.             <xsl:when test="$pow = 0">
  122.                 <xsl:value-of select="$tmpResult"/>
  123.             </xsl:when>
  124.             <xsl:otherwise>
  125.                 <xsl:call-template name="pow">
  126.                     <xsl:with-param name="base" select="$base"/>
  127.                     <xsl:with-param name="pow" select="$pow + $incr"/>
  128.                     <xsl:with-param name="tmpResult" select="$result"/>
  129.                 </xsl:call-template>
  130.             </xsl:otherwise>
  131.         </xsl:choose>
  132.     </xsl:template>
  133.   
  134. </xsl:stylesheet>